const Sequelize = require('sequelize')
let db = require('../config/db')

let User = db.define('user',{
    uid:{
        type: Sequelize.INTEGER,
        field: 'uid',
        primaryKey:true,
        autoIncrement: true,
        comment: "主键，自增"
    },
    account:{
        type:Sequelize.STRING,
        comment:"账号",
        defaultValue: null
    },
    password:{
        type:Sequelize.STRING,
        comment:"密码",
        defaultValue: null
    },
    type:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'当前状态 0 普通用户 1企业用户'
    },
    openid:{
        type: Sequelize.STRING,
        comment:"用户的唯一标识"
    },
    invite_code:{
        type: Sequelize.STRING,
        comment:"邀请码"
    },
    Inviter:{
        type: Sequelize.STRING,
        comment:'邀请者'
    },
    nickname:{
        type:Sequelize.STRING,
        comment:"用户昵称",
        defaultValue: null
    },
    sex:{
        type: Sequelize.INTEGER,
        defaultValue:0,
        comment:'户的性别，值为1时是男性，值为2时是女性，值为0时是未知'
    },
    country:{
        type:Sequelize.STRING,
        comment:"国家，如中国为CN",
        defaultValue: null

    },
    headimgurl:{
        type:Sequelize.STRING,
        comment:"headimgurl",
        defaultValue: null

    },
    unionid:{
        type: Sequelize.STRING,
        comment:'只有在用户将公众号绑定到微信开放平台帐号后，才会出现该字段。',
        defaultValue:null
    },
    username: {
        type: Sequelize.STRING,
        field: 'username',
        comment:'用户名'
    },
    isVerify:{
        type: Sequelize.INTEGER,
        defaultValue:0,
        comment:'认证状态,0未认证，1已认证'
    },
    balance:{
        type: Sequelize.INTEGER,
        defaultValue:0,
        comment:'余额'
    },
    profit:{
        type: Sequelize.INTEGER,
        defaultValue:0,
        comment:'收益'
    },
    isDel:{
        type: Sequelize.INTEGER,
        defaultValue:0,
        comment:'状态，是否删除'
    },
    ban:{
        type: Sequelize.INTEGER,
        defaultValue:0,
        comment:'是否封禁'
    },
    deletedAt: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('deletedAt')).format('YYYY-MM-DD HH:mm:ss');
        }
    },
    createdAt: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm:ss');
        }
    },
    updatedAt: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm:ss');
        }
    },
},{
    freezeTableName:true,
    paranoid:true,
    timestamps:true
})
let user = User.sync();

module.exports = User
